package com.junjie.services.impl;

import com.junjie.dao.RDeviceDao;
import com.junjie.entity.RDevice;
import com.junjie.services.RDeviceService;
import com.junjie.utils.CommonParams;
import com.junjie.utils.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RDeviceServiceImpl implements RDeviceService {

    @Autowired
    private RDeviceDao rDeviceDao;

    //通用查询接口
    @Override
    public List<RDevice> getRDevices(RDevice rDevice) {
        return rDeviceDao.getRDevices(rDevice);
    }

    //根据 id rId status来查询对应的设备
    @Override
    public RDevice getRDeviceByIdRIdStatus(Integer id, Integer rId, Integer status) {
        return rDeviceDao.getRDeviceByIdRIdStatus(id, rId, status);
    }

    //插入一条设备信息的方法
    @Override
    public CommonResult<Integer> insertRDevice(RDevice rDevice) {
        return new CommonResult<>(CommonParams.SUCCESS, "设备添加成功！", rDeviceDao.insertRDevice(rDevice));
    }

    //修改一条设备的信息
    @Override
    public CommonResult<Integer> updateRDeviceById(RDevice rDevice) {
        return new CommonResult<>(CommonParams.SUCCESS, "设备信息插入成功!", rDeviceDao.updateAndDelete(rDevice));
    }

    //删除一条数据的方法
    @Override
    public CommonResult<Integer> deleteRDevice(Integer id) {
        RDevice rDevice = new RDevice();
        rDevice.setId(id);
        rDevice.setStatus(0);
        return new CommonResult<>(CommonParams.SUCCESS, "设备删除成功！", rDeviceDao.updateAndDelete(rDevice));
    }
}
